/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package line.table;

import hxg.portmgr.core.dao.impl.jaxb.LineDaoJaxbImpl;
import hxg.portmgr.core.dao.LineDAO;
import hxg.portmgr.core.device.Device;
import hxg.portmgr.core.device.intf.Intf;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.logging.Logger;
import hxg.portmgr.core.line.Line;

/**
 *
 * @author hxg
 */
public class LineTable {

    private static final Logger logger = Logger.getLogger(LineTable.class.getName());
    final static LineDAO dao = new LineDaoJaxbImpl();

    public static Line connect(Intf inf1, Intf inf2) {
        return dao.connect(inf1, inf2);
    }

    public static Line connect(Intf inf1, String connPoint) {
        return dao.connect(inf1, connPoint);
    }

    public static Line getLine(Intf inf) {
        return dao.getLine(inf);
    }

    public static Collection<Line> getLines() {
        return dao.getLines();
    }

    public static Set<Line> getLineOfDevice(Device dev) {
        Collection<Line> alllines = dao.getLines();
        Set<Line> lines = new LinkedHashSet();
        for (Line line : alllines) {
            for (Intf inf : line.getIntfs()) {
                if (inf.getDevice().equals(dev)) {
                    lines.add(line);
                }
            }
        }
        return lines;
    }

    public static Set<Device> getLinkedDevice(Line line) {
        LinkedHashSet<Device> devs = new LinkedHashSet();
        for (Intf inf : line.getIntfs()) {
            devs.add(inf.getDevice());
        }
        return devs;
    }

    public static Set<Device> getLinkedDevice(Device dev) {
        Set<Device> devs = new HashSet();
        Set<Line> lines = getLineOfDevice(dev);
        for (Line line : lines) {
            devs.addAll(getLinkedDevice(line));
        }
        return devs;
    }

    public static boolean isConnected(Intf inf) {
        return dao.isConnected(inf);
    }

    public static Line disConnect(Intf inf) {
        return dao.disConnect(inf);
    }

    public static Intf getOtherIntf(Intf inf) {
        return dao.getOtherIntf(inf);
    }

    public static String getOtherSideName(Intf inf) {
        return dao.getOtherSideName(inf);
    }

    public static void save() {
        dao.save();
    }

    public static void load() {
        dao.load();
    }

    public static LineDAO getDao() {
        return dao;
    }
}
